package com.dhcc.sds.busi.controller;

import com.alibaba.fastjson.JSONArray;
import com.dhcc.cdc.busi.service.ICdcHospitalService;
import com.dhcc.cdc.busi.service.ICdcLocationService;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.sds.base.service.ISdsCommonService;
import com.dhcc.sds.base.service.ISdsQcentityService;
import com.dhcc.sds.busi.service.IAnalysisSdsMstaService;
import com.dhcc.sds.busi.service.ISdsQcincaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @version 1.0 DHCC
 * @Description: 单病种专员填报统计页面
 * @author:jumper
 * @date:2022年05月13日09:58:22
 * @Copyright: (c) DHCC All rights reserved.
 */
@Controller
@RequestMapping("${sys.backendPath}/analysis/sdsdoc")
public class AnalysisSdsMstaDocController extends BaseController {

    private String PREFIX = "/backend/sds/analysis/";

    
    @Autowired
    private IAnalysisSdsMstaService analysisSdsMstaService;

    @Autowired
    private ICdcHospitalService cdcHospitalService;

    @Autowired
    private ICdcLocationService cdcLocationService;

    @Autowired
    private ISdsQcentityService sdsQcentityService;

    @Autowired
    private ISdsQcincaseService sdsQcincaseService;

    @Autowired
    private ISdsCommonService sdsCommonService;
    
    @RequestMapping("")
    public String index(Model model) {
        //获取部门信息
        JSONArray officMap = cdcHospitalService.getOfficeMap();
        //默认加载所有科室
        JSONArray departMap = sdsCommonService.getDepartMap(new HashMap<>());
        //获取病种的年份
        JSONArray yearMap = sdsQcincaseService.getYearMap();
        //获取病种的月份
        JSONArray monthMap = sdsQcincaseService.getMonthMap();
        model.addAttribute("officeMap",officMap);
        model.addAttribute("departMap",departMap);
        model.addAttribute("yearMap",yearMap);
        model.addAttribute("monthMap",monthMap);
        model.addAttribute("hospitalId",sdsCommonService.getHospIdBySysUser());
        return PREFIX + "sdsdoc.html";
    }
    
    @RequestMapping("selectSdsDocTable")
    @ResponseBody
    public Object selectSdsDocTable(@RequestParam Map<String, Object> params) {
        // 查询登录用户关联科室
        List<String> deptIds = sdsCommonService.getDeptIdsBySysUser();
        params.put("userLinkDepts", deptIds);
        return analysisSdsMstaService.selectSdsQcDocTable(params);
    }

    @RequestMapping("toLocCase")
    public String toLocCase(@RequestParam Map<String, Object> map,Model model) {

        model.addAttribute("startDateV", map.get("startDate"));
        model.addAttribute("endDateV", map.get("endDate"));
        model.addAttribute("officeV", map.get("office"));
        model.addAttribute("departV", map.get("depart"));
        model.addAttribute("qcEntityV", map.get("qcEntity"));
        model.addAttribute("desc",map.get("desc"));
        return PREFIX + "loccase.html";
    }

}
